<?php
declare (strict_types=1);

namespace app\admin\middleware;

use addons\Builder\driver\trait\Admin;

class Verify
{

    use Admin;

    /**
     * @var string[] 无需验证方法，* 代表全部，格式：控制器/方法名
     */
    protected $allow = [
        '*/getList',
        'index/*'
    ];

    public function handle($request, \Closure $next)
    {
        $result = $this->verify();

        return is_array($result) ? match ($result['type']) {
                1 => redirect($result['url']),
                -1 => $this->error($result['msg']),
                default => $this->error('加载失败')
            } : $next($result);
    }
}
